package cn.youqu.happy.module.youqu.dal.mysql.userComment;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userComment.vo.UserCommentExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userComment.vo.UserCommentPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userComment.UserCommentDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户回复 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserCommentMapper extends BaseMapperX<UserCommentDO> {
    UserCommentDO findOneByIdAndTellId(@Param("id") Integer id, @Param("tellId") Integer tellId);

    UserCommentDO findByIdAndUid(@Param("id") Integer id, @Param("uid") Long uid);

    int updateNickNameByUid(@Param("updatedNickName") String updatedNickName, @Param("uid") Long uid);

    int updateAvatarByUid(@Param("updatedAvatar") String updatedAvatar, @Param("uid") Long uid);


    default PageResult<UserCommentDO> selectPage(UserCommentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserCommentDO>()
                .eqIfPresent(UserCommentDO::getUid, reqVO.getUid())
                .eqIfPresent(UserCommentDO::getAvatar, reqVO.getAvatar())
                .likeIfPresent(UserCommentDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserCommentDO::getPid, reqVO.getPid())
                .eqIfPresent(UserCommentDO::getComment, reqVO.getComment())
                .eqIfPresent(UserCommentDO::getTellId, reqVO.getTellId())
                .betweenIfPresent(UserCommentDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserCommentDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserCommentDO::getId));
    }

    default List<UserCommentDO> selectList(UserCommentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserCommentDO>()
                .eqIfPresent(UserCommentDO::getUid, reqVO.getUid())
                .eqIfPresent(UserCommentDO::getAvatar, reqVO.getAvatar())
                .likeIfPresent(UserCommentDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserCommentDO::getPid, reqVO.getPid())
                .eqIfPresent(UserCommentDO::getComment, reqVO.getComment())
                .eqIfPresent(UserCommentDO::getTellId, reqVO.getTellId())
                .betweenIfPresent(UserCommentDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserCommentDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserCommentDO::getId));
    }

}
